package com.jxl.domain.service.impl;

import com.jxl.domain.entity.AuthRolePermissionBO;
import com.jxl.domain.service.AuthRolePermessionDomainService;
import com.jxl.infra.basic.entity.AuthRolePermission;
import com.jxl.infra.basic.service.AuthRolePermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermessionDomainService {

    @Resource
    private AuthRolePermissionService authRolePermissionService;

    @Override
    public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
        List<AuthRolePermission> list = new ArrayList<>();
        Long roleId = authRolePermissionBO.getRoleId();

        //进行组装
        authRolePermissionBO.getPermissionIdList().forEach(id->{
            AuthRolePermission authRolePermission = new AuthRolePermission();
            authRolePermission.setRoleId(roleId);
            authRolePermission.setPermissionId(id);
            list.add(authRolePermission);
        });
        int i = authRolePermissionService.batchInsert(list);
        return i>0;
    }
}
